package com.vvitt.kotlinhiltcarhome.viewmodel

import androidx.hilt.lifecycle.ViewModelInject
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.vvitt.kotlinhiltcarhome.model.CarBrandItemModel
import com.vvitt.kotlinhiltcarhome.repository.BaseRepository

/**
 * @ClassName CarBrandViewModel
 * @author please call me police uncel
 * @since 2023/5/25.
 * @email 110
 * @Version: V1.0.0
 * @desciption 汽车品牌业务处理的Viewmodel
 **/
class CarBrandViewModel @ViewModelInject constructor(
    private val carBrandRepository: BaseRepository
): ViewModel(){
    val data: LiveData<PagingData<CarBrandItemModel>> =
        carBrandRepository
            .fetchCarBrandList()
             //缓存，以防屏幕旋转等情况重新加载数据
            .cachedIn(viewModelScope)
            .asLiveData()

}